#include "HighScore.h"
#include "../SGD Wrappers/SGD_GraphicsManager.h"
#include "../SGD Wrappers/SGD_InputManager.h"
#include "MainMenuState.h"
#include "Game.h"
#include "BitmapFont.h"
#include <fstream>
#include "GameplayState.h"
#include <list>

HighScore* HighScore::GetInstance()
{
	static HighScore s_Instace;

	return &s_Instace;
}

void HighScore::Enter()
{
	m_hBackgroundImage = SGD::GraphicsManager::GetInstance()->LoadTexture("resource/graphics/Background.jpg");


}
void HighScore::Exit()
{
	SGD::GraphicsManager::GetInstance()->UnloadTexture(m_hBackgroundImage);
}

void HighScore::Update(float dt)
{

}

void HighScore::Render()
{
	BitmapFont temp;
	temp.Initialize();
	Game*game = Game::GetInstance();

	SGD::GraphicsManager::GetInstance()->DrawTexture(m_hBackgroundImage, { 0, 0 }, {}, {}, {}, {1,0.75});
	
	
	
	SGD::String scores;
	scores = L"High Scores\n\n";

	Game::Save* save = Game::GetInstance()->GetSave();

	save->Score.sort([](float one, float two) -> bool {
		return one < two;
	});

	for each (float score in save->Score)
	{
		if (score < 10.f)
			scores += L"0";
		scores += std::to_wstring(score);
		int trunck = scores.find_last_of(L'.');
		scores.erase(scores.begin() + trunck + 3, scores.end());
		scores += L'\n';
	}

	temp.Draw(&scores,(int)(game->GetScreenWidth() / 2 - 30*1.5f * 4), 10, 1.5f, SGD::Color(255,0,0));

}

bool HighScore::Input()
{

	if (SGD::InputManager::GetInstance()->IsKeyPressed(SGD::Key::Escape)
		|| SGD::InputManager::GetInstance()->IsButtonDown(0,1))
		Game::GetInstance()->ChangeState(MainMenuState::GetInstance());

	return true;
}